package com.yanqu.road.server.manger;

import com.yanqu.road.entity.servercenter.DataUploadInfo;
import com.yanqu.road.logic.bussiness.servercenter.ServerBussiness;
import com.yanqu.road.logic.config.ChannelConfig;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.utils.ConfigHelper;
import com.yanqu.road.utils.string.StringUtils;

/**
 * @Author wpj
 * @Date 2020/9/15
 */
public class DataUploadInfoMgr extends TempMgr {

    private static DataUploadInfo dataUploadInfo;

    public static DataUploadInfo getDataUploadInfo() {
        return dataUploadInfo;
    }

    /**
     * 是否允许上传 保证4个字段都不为空
     *
     * @return
     */
    public static boolean isAllowUpload() {
        if (ChannelConfig.LOG_UPLOAD == 1 &&
                dataUploadInfo != null &&
                !StringUtils.isNullOrEmpty(dataUploadInfo.getAnalysisBackendUrl()) &&
                !StringUtils.isNullOrEmpty(dataUploadInfo.getCommonBackendUrl()) &&
                !StringUtils.isNullOrEmpty(dataUploadInfo.getAppId()) &&
                !StringUtils.isNullOrEmpty(dataUploadInfo.getAppSecret())) {
            return true;
        }

        return false;
    }

    @Override
    public boolean reloadData() throws Exception {
        dataUploadInfo = ServerBussiness.getDataUploadInfo(ServerListMgr.getServerInfo(ConfigHelper.getLong("serverId")).getChannelId());
        return true;
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean stop() {
        return true;
    }
}
